<?php
/*
 * Created on 04.01.2006
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 
class h_selectBoxHandler
{

    var $value;
    var $optiontext;
    var $selected;

    function startElement (& $sender, $attrs)
    {
        if (!$attrs['value'])
        {
            die ("Attribute value is missing in out tag\n");
        }
        if (!$attrs['name'])
        {
            die ("Attribute name is missing in out tag\n");
        }
        $value = '';
        if ($attrs['selected'])
        {
            $this->selected = $attrs['selected'];
        }
        if ($attrs['optionvalue'])
        {
            $this->optionvalue = $attrs['optionvalue'];
            $this->value = ' value=\\"".$selbox[$i]['.$attrs['optionvalue'].']."\\"';
        }
        if (!$attrs['optiontext'])
        {
            die ("Attribute optiontext is missing in out tag\n");
        }
        if ($attrs['style'])
        {
            $style = substr($attrs['style'], 1, strlen($attrs['style'])-2);
            if (preg_match('/${/', $style))
                die ("Attribute var must not contain EL code\n");
            $style = ' style=\\"'.$style.'\\"';
        }
        $this->optiontext = $attrs['optiontext'];
        $sender->appendCode('$selbox = '.$attrs['value'].'; print "<select name=\\"".'.$attrs['name'].'."\\"'.$style.'>"; ');
    }
    
    function endElement (& $sender)
    {
        $code  = 'for ($i = 0; $i < count($selbox); $i++)' .
                        '{ print "<option'.$this->value.'";';
        if ($this->selected)
            $code .= 'if ('.$this->selected.' == $selbox[$i]['.$this->optionvalue.']) print " selected=\\"selected\\"";';
        $code .= 'print ">".$selbox[$i]['.$this->optiontext.']."</option>\n"; }'.
                'print "</select>";'."\n";
        unset($this->selected);
        $sender->appendCode($code);
    }

} 

?>
